#ifndef RINGBUFFER_H
#define RINGBUFFER_H

#define USE_MUTEX 0

#if (USE_MUTEX == 1)
	#include "bcti_Mutex.h"
#endif
namespace lzpLib{
// no lock, only for 1 read thread/1 write thread, or all in 1 thread
class RingBuffer{
public:
    /*buffer size must is power of 2 and >=2*/
    RingBuffer();
    RingBuffer(char* buffer, unsigned int size);
    bool allocate(unsigned int size);
    ~RingBuffer();
    unsigned int read(char* buffer, unsigned int len);
    unsigned int skip(unsigned int len);
    unsigned int write(char* data, unsigned int len);
    unsigned int backwardSeek(unsigned int len);//only for special usage, like some file parser. only use all in 1 thread
    unsigned int length(void);
    unsigned int space(void);
    unsigned int size(void);
    bool isFull(void);
    void reset(void);

    void print(void);

    //long getRmvbIndexOffset();
public:
    char* buffer_;
    bool allocated_;
    volatile unsigned int read_;
    volatile unsigned int write_;
    unsigned int size_;

#if (USE_MUTEX == 1)
	Mutex m_mutex_;		//lock
#endif
};
}

#endif // RINGBUFFER_H
